/* eslint-disable no-useless-escape */
class UrlParse {
    constructor(url) {
        this.url = url || window.location.href
        this.reg = /(([^:]+:)\/\/(([^:\/\?#]+)(:\d+)?))(\/[^?#]*)?(\?[^#]*)?(#.*)?/
        this.argKey = ['href', 'origin', 'protocol', 'host', 'hostname', 'port', 'pathname', 'search', 'hash']
    }
    getUrlParams() {
        let result = {}
        let i
        let len = this.argKey.length
        let match = this.reg.exec(this.url)
        if (match) {
            for (i = len - 1; i >= 0; --i) {
                result[this.argKey[i]] = match[i] ? match[i] : ''
            }
        }
        return result
    }
}

export {
    UrlParse
}